const crawler = require('../../libs/crawler'),
      { crawlerConf } = require('../../config/config');

crawler({

  url: crawlerConf.url.course,
  field: 'course', //增加一个字段爬取第二页
  callback () {
    const $ = window.$,
          $item = $('.course-card-list-multi-wrap .course-card-item');
    
    const data = [];

    $item.each((index, item) => {
      const $el = $(item),
            $itemLk = $el.find('.item-img-link');
          
      const dataItem = {
        cid: $itemLk.attr('data-id'),
        href: $itemLk.prop('href'),
        posterImgUrl: $itemLk.find('.item-img').prop('src').replace('webp', ''),
        courseName: $itemLk.find('.item-img').prop('title'),
        price: $el.find('.item-price').text() === '免费' ? '0' : $el.find('.item-price').text().slice(1),
        description: $el.find('.item-status-step').text(),
        studentCount: parseInt($el.find('.item-user').text()),
        posterImgKey: ''
      };

      data.push(dataItem);
    }); 

    return data;
  }

})